{{extend "base.html"}}

{{block body_tag}}
<body class="gray-bg">
{{end}}

{{block content}}

    
        <!--禁止弹出的model按任意键消失data-backdrop="static" data-keyboard="false"-->
        <div class="modal fade" style="display:none;" id="modaladd" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

        <div class="modal fade" style="display:none;" id="modaledit" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

        <div class="modal fade" style="display:none;" id="modalupdate" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->

    <div class="wrapper wrapper-content animated fadeInRight">

    <!-- Panel Other -->
        <div class="ibox float-e-margins">

            <div class="ibox-content">
                <div class="row row-lg">

                    <div class="col-sm-12">
                        <!-- Example Events -->
                        <div class="example-wrap">

                            <div class="example">

                                <div class="btn-group hidden-xs" id="toolbar" role="group">
                                    <a data-toggle="modal" class="btn btn-outline btn-default" id="myadd" href="javascript:void(0)" data-target="#modaladd">
                                        <i class="glyphicon glyphicon-plus" aria-hidden="true">添加</i>
                                    </a>

                                    <a data-toggle="modal" class="btn btn-outline btn-default" id="myedit" href="javascript:void(0)" data-target="#">
                                        <i class="glyphicon glyphicon-edit" aria-hidden="true">编辑</i>
                                    </a>
                                    <button type="button" id="remove" name="remove" class="btn btn-outline btn-default">
                                        <i class="glyphicon glyphicon-trash" aria-hidden="true">删除</i>
                                    </button>
                                    <button type="button" id="refresh" name="refresh" class="btn btn-outline btn-default">
                                        <i class="glyphicon glyphicon-refresh" aria-hidden="true">刷新</i>
                                    </button>
                                    <a data-toggle="modal" class="btn btn-outline btn-default" id="myupdate" href="javascript:void(0)" data-target="#">
                                        <i class="glyphicon glyphicon-save" aria-hidden="true">更新源</i>
                                    </a>
                                    <button type="button" id="publish" name="publish" class="btn btn-outline btn-default">
                                        <i class="glyphicon glyphicon-open" aria-hidden="true">发布</i>
                                    </button>
                                </div>

                                <table  id="table"
                                        data-toggle="table" 
                                        data-url="/webprojectpost/subversionlist" 
                                         data-height="726"
                                        {{#支持手机端}}
                                        data-mobile-responsive="true"
                                        data-toolbar="#toolbar"
                                        {{#排序}}
                                        data-sort-name="id"
                                        data-sort-order = "desc"
                                        {{#服务端分页}}
                                        data-side-pagination="server"
                                        data-pagination="true"
                                        data-page-size="16"
                                        data-page-list="[16, 50, 100, All]"
                                        >
                                    <thead>
                                        <tr>
                                            <th data-field="state" data-checkbox="true"></th>
                                            <th data-field="id">ID</th>
                                            <th data-field="svn_name" data-sortable="true">仓库名称</th>
                                            <th data-field="username">管理用户</th>
                                            <th data-field="svn_username">用户名</th>
                                            <th data-field="svn_passwd">密码</th>
                                            <th data-field="svn_url" data-sortable="true">仓库地址</th>
                                            <th data-field="svn_webip_client">本地源目录</th>
                                            <th data-field="rsync_ignore_dir">忽略同步目录</th>
                                            <th data-field="svn_webip_client">远程web ip</th>
                                            <th data-field="rsync_module" data-sortable="true">rsync模块</th>
                                            <th data-field="svn_comment">备注</th>
                                        </tr>
                                    </thead>
                                </table>
                                

                            </div>
                        </div>
                        <!-- End Example Events -->
                    </div>
                </div>
            </div>
        </div>
        <!-- End Panel Other -->
        
    </div>
    {{end}}
    
    {{block after_footer}}
    
    <script>
    
        var $table = $('#table');
        var $buttonremove = $('#remove');
        var $myadd = $('#myadd');
        var $myedit = $('#myedit');
        var $myupdate = $('#myupdate');
        var $buttonrefresh = $('#refresh');
        var $buttonupdate = $('#myupdate');
        var $buttonpublish = $('#publish');


        $(function () {

            //隐藏ID字段
            $table.bootstrapTable('hideColumn', 'id');

            //每次加载modal清除之前的数据,modal的ajax缓存bug
            $('body').on('hidden.bs.modal', '.modal', function () {
                $(this).removeData('bs.modal');
            });

            $myadd.click(function(){
                var timestamp=Math.round(new Date().getTime()/1000);
                $myadd.attr('href','/webproject/subversionlistadd?time=' + timestamp);
            });
            
            $myedit.click(function () {
                var timestamp=Math.round(new Date().getTime()/1000);
                //得到选中的记录
                var id = $.map($table.bootstrapTable('getSelections'), function (row) {
                    return row.id;
                });
                if(id.length == 1){
                    $myedit.attr('data-target',"#modaledit");
                    $myedit.attr('href','/webproject/subversionlistedit?time=' + timestamp + '&id=' + id);
                }else{
                    $myedit.attr('data-target',"#");
                    swal("提示", "同一时间只能编辑一条记录！", "error");
                }
            });
            
            //删除
            $buttonremove.click(function () {
                var ids = $.map($table.bootstrapTable('getSelections'), function (row) {
                    return row.id;
                });
                
                if(ids.length >= 1){
                    swal({
                        title: "您确定要删除选择的条目吗",
                        text: "删除后将无法恢复，请谨慎操作！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "删除",
                        cancelButtonText: "取消",
                        closeOnConfirm: false
                    }, function () {
                        $.ajax({
                            type:"POST",
                            url : '/webproject/subversionlistdel',
                            data : {
                                id : ids.join(",")
                            },
                            dataType : 'json',
                            success : function(d) {
                                if (d.status == '200'){
                                    $table.bootstrapTable('remove', {
                                        field: 'id',
                                        values: ids
                                    });
                                    $table.bootstrapTable('refresh');
                                    swal("删除成功！", "您已经永久删除了这条信息。", "success");
                                }else{
                                    swal("删除失败！", d.msg, "error");
                                }
                            }
                        });
                    });
                }else{
                    swal("提示", "请选择要删除的记录！", "error");
                }
            });

            //刷新
            $buttonrefresh.click(function () {
                $table.bootstrapTable('refresh');
                //重置搜索，搜索为空则无反应
                //$table.bootstrapTable('resetSearch');
            });

            //更新
            $buttonupdate.click(function () {
                var timestamp=Math.round(new Date().getTime()/1000);
                //得到选中的记录
                var id = $.map($table.bootstrapTable('getSelections'), function (row) {
                    return row.id;
                });
                if(id.length == 1){
                    $myupdate.attr('data-target',"#modalupdate");
                    $myupdate.attr('href','/webproject/subversionlistupdate?time=' + timestamp + '&id=' + id);
                }else{
                    $myupdate.attr('data-target',"#");
                    swal("提示", "同一时间只能选择一条记录！", "error");
                }
            });

            //发布
            $buttonpublish.click(function () {
                var id = $.map($table.bootstrapTable('getSelections'), function (row) {
                    return row.id;
                });
                
                if(id.length == 1){
                    swal({
                        title: "您确定要发布到正式吗",
                        text: "发布后原服务器代码会被覆盖",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "发布",
                        cancelButtonText: "取消",
                        closeOnConfirm: false
                    }, function () {
                        $.ajax({
                            type:"POST",
                            url : '/webproject/codepublish',
                            data : {
                                id : id
                            },
                            dataType : 'json',
                            success : function(d) {
                                if (d.status == '200'){
                                    swal("成功！", d.msg, "success");
                                }else{
                                    swal("失败！", d.msg, "error");
                                }
                            }
                        });
                    });
                }else{
                    swal("提示", "请选择要发布的仓库！", "error");
                }
            });

        });
    </script>
    {{end}}
